package team.archai.nexus.boot.tool;

import cn.hutool.extra.servlet.ServletUtil;
import com.alibaba.fastjson.JSON;
import team.archai.nexus.boot.constant.HttpConstant;
import team.archai.nexus.boot.constant.HttpEnum;


import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

/**
 * @description: http工具类
 * @author: lishibin
 * @create: 2020-07-11 20:38
 **/
public class HttpUtil extends cn.hutool.http.HttpUtil {

    public static void responseJson(ServletResponse response, Object object) {
        response.setCharacterEncoding(HttpConstant.Charset.UTF_8);
        ServletUtil.write((HttpServletResponse) response, JSON.toJSONString(object), HttpConstant.ContentType.JSON);
    }

    public static void responseError(ServletResponse response, HttpEnum httpEnum, Object object) {
        response.setCharacterEncoding(HttpConstant.Charset.UTF_8);
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        httpServletResponse.setStatus(httpEnum.getCode());
        ServletUtil.write(httpServletResponse, JSON.toJSONString(object), HttpConstant.ContentType.JSON);
    }



}
